package com.bawei.homegroup.bindadapter;



import android.content.Context;



import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

public class SmartAdapter {

    @BindingAdapter(value = {"refreshListener","loadMoreListener"},requireAll = false)
    public static void SmartBind(SmartRefreshLayout smartRefreshLayout,
                                 OnRefreshListener refreshListener,
                                 OnLoadMoreListener loadMoreListener){

        smartRefreshLayout.setEnableLoadMore(true);
        smartRefreshLayout.setEnableRefresh(true);
        smartRefreshLayout.setRefreshHeader(new ClassicsHeader(smartRefreshLayout.getContext()));
        smartRefreshLayout.setRefreshFooter(new ClassicsFooter(smartRefreshLayout.getContext()));
        smartRefreshLayout.setOnRefreshListener(refreshListener);
        smartRefreshLayout.setOnLoadMoreListener(loadMoreListener);


    }
    @BindingAdapter(value = {"finishLoad","finishRefresh"})
    public static  void SmartLoadRefreshBind(SmartRefreshLayout smartRefreshLayout,boolean finishLoad,boolean finishRefresh){
        if (finishRefresh)
            smartRefreshLayout.finishRefresh();
        if (finishLoad)
            smartRefreshLayout.finishLoadMore();
    }

}
